#!/bin/bash

i=$1
pdbid=${i%%.*}

printf "8" | gmx pdb2gmx -f ${pdbid}.pdb -o ${pdbid}_processed.gro -water spc -ignh

#printf "r 4 | r 30 | r 31 | r 61 & ! a H*\n name 10 Motif\n q\n" | gmx make_ndx -f ${pdbid}_processed.gro -o index.ndx
#gmx editconf -f ${pdbid}_processed.gro -n index.ndx -o ${pdbid}_processed.pdb -label A

printf "r 4 | r 30 | r 31 | r 61 & ! a H*\n name 10 Motif\n q\n" | gmx make_ndx -f ${pdbid}_processed.gro -o index.ndx

printf "10" | gmx genrestr -f ${pdbid}_processed.gro -o posre.itp -fc 100000 -n index.ndx

gmx editconf -f ${pdbid}_processed.gro -o ${pdbid}_newbox.gro -bt cubic -c -d 1.0

gmx solvate -cp ${pdbid}_newbox.gro -cs spc216.gro -p topol.top -o ${pdbid}_solvate.gro

gmx grompp -f ions.mdp -c ${pdbid}_solvate.gro -p topol.top -o next.tpr -maxwarn 1

printf "13" | gmx genion -s next.tpr -o ${pdbid}_solv_ions.gro -p topol.top -pname NA -nname CL -conc 0.15 -neutral

gmx grompp -f em.mdp -c ${pdbid}_solv_ions.gro -r ${pdbid}_solv_ions.gro -p topol.top -o em.tpr

gmx mdrun -v -deffnm em -ntmpi 64

gmx editconf -f em.gro -o em.pdb
